package web.audio;

import java.util.List;

import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.wicketstuff.html5.media.MediaSource;
import org.wicketstuff.html5.media.audio.Html5Audio;

public class ReproductorDeAudio extends Html5Audio{
	private static final long serialVersionUID = 1L;

	public ReproductorDeAudio(String id, final IModel<List<MediaSource>> model) {
		super(id, model);
		this.setOutputMarkupId(true);
		add(new AjaxEventBehavior("onended") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onEvent(AjaxRequestTarget target) {
				List<MediaSource> listaDeReproduccion = model.getObject();
				listaDeReproduccion.add(listaDeReproduccion.remove(0));
				target.add(ReproductorDeAudio.this);
			}
		});
	}

	@Override
	protected boolean isAutoPlay() {
		return true;
	}
	@Override
	protected boolean isControls() {
		return true;
	}
}